/*
 * Pinochle.java
 * 
 * Client program that uses Player.java, Card.java, and RandomizedQueue.java
 * to read in a deck of pinochle cards and randomly distribute them to four
 * players.
 */

import java.io.*;
import java.util.*;
public class Pinochle {	
	
	public static void main(String[] args) throws FileNotFoundException, IOException {
		// Randomized queue to store a deck of cards.
		RandomizedQueue<Card> pinochle = new RandomizedQueue<Card>();		
		
		// Reads the deck in and stores it.
		File inFile = new File("src/pinochleDeck.txt");
		FileReader fileReader = new FileReader(inFile);
		BufferedReader bufReader = new BufferedReader(fileReader);
		Scanner scanner = new Scanner(bufReader);
		Card current;
		while(scanner.hasNext()){
			current = new Card(scanner.next(), scanner.next());
			pinochle.add(current);
		}
		
		
		/*while(!StdIn.isEmpty()){
			current = new Card(StdIn.readString(), StdIn.readString());
			pinochle.add(current);
		}*/
		
		// RandomizedQueue is utilized to randomly deal the deck out.
		// Cards dealt three at a time.
		Player p1 = new Player("Player 1, Team 1", 12);
		for(int i=0; i<p1.handSize() && !pinochle.isEmpty(); i+=3){
			p1.addToHand((Card)pinochle.remove());
			p1.addToHand((Card)pinochle.remove());
			p1.addToHand((Card)pinochle.remove());
		}
		p1.sortHand();
		
		Player p2 = new Player("Player 2, Team 2", 12);
		for(int i=0; i<p1.handSize() && !pinochle.isEmpty(); i+=3){
			p2.addToHand((Card)pinochle.remove());
			p2.addToHand((Card)pinochle.remove());
			p2.addToHand((Card)pinochle.remove());
		}
		p2.sortHand();
		
		Player p3 = new Player("Player 3, Team 1", 12);
		for(int i=0; i<p1.handSize() && !pinochle.isEmpty(); i+=3){
			p3.addToHand((Card)pinochle.remove());
			p3.addToHand((Card)pinochle.remove());
			p3.addToHand((Card)pinochle.remove());
		}
		p3.sortHand();
		
		Player p4 = new Player("Player 4, Team 2", 12);
		for(int i=0; i<p1.handSize() && !pinochle.isEmpty(); i+=3){
			p4.addToHand((Card)pinochle.remove());
			p4.addToHand((Card)pinochle.remove());
			p4.addToHand((Card)pinochle.remove());
		}
		p4.sortHand();
		
		System.out.println("Player 1 hand");
		p1.showHand();
		System.out.println();
		
		System.out.println("Player 2 hand");
		p2.showHand();
		System.out.println();
		
		System.out.println("Player 3 hand");
		p3.showHand();
		System.out.println();
		
		System.out.println("Player 4 hand");
		p4.showHand();
		System.out.println();
	}

}
